home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gnugo1_1.lha / gnugo / endgame.c < prev    next >
C/C++ Source or Header  |  1989-03-07  |  3KB  |  132 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35.  
  36. #include <stdio.h>
  37.  
  38. #define EMPTY 0
  39.  
  40. extern unsigned char p[19][19];
  41. extern int mymove, umove;
  42. extern int mk, uk;  /* piece captured */
  43.  
  44. endgame()
  45. /* count pieces and announce the winner */
  46. {
  47.  char an[10];
  48.  int i, j, mtot, utot, cont;
  49.  
  50.  printf("\nTo count score, we need the following steps:\n");
  51.  printf("First, I need you to remove all dead pieces on the board.\n");
  52.  printf("Second, I need you to fill in neutral territories with ");
  53.  printf("pieces.\n");
  54.  printf("Last, I will fill in all pieces and anounce the winner.\n");
  55.  
  56. /* remove dead pieces */
  57.  printf("\nFirst, you should enter the dead pieces (blank and white) to");
  58.  printf(" be removed.  Enter\n");
  59.  printf(" 'stop' when you have finished.\n");
  60.  
  61.  cont = 1;
  62.  do {
  63.      printf("Dead piece? ");
  64.      scanf("%s", an);
  65.      if (strcmp(an, "stop"))
  66.        {
  67.     getij(an, &i, &j);
  68.     if (p[i][j] == mymove)
  69.       {
  70.        p[i][j] = EMPTY;
  71.        mk++;
  72.      }
  73.     else
  74.        if (p[i][j] == umove)
  75.          {
  76.           p[i][j] = EMPTY;
  77.           uk++;
  78.         }
  79.     showboard();
  80.       }
  81.     else
  82.        cont = 0;
  83.    }
  84.  while (cont);
  85.  
  86. /* fill in neutral */
  87.  printf("Next, you need to fill in pieces (black and white) in all neutral");
  88.  printf(" territories.\n");
  89.  printf("Enter your and my pieces alternately and enter 'stop' when finish\n");
  90.  cont = 1;
  91.  
  92.  do {
  93.      printf("Your piece? ");
  94.      scanf("%s", an);
  95.      if (strcmp(an, "stop"))
  96.        {
  97.     getij(an, &i, &j);
  98.     p[i][j] = umove;
  99.     printf("My piece? ");
  100.     scanf("%s", an);
  101.     getij(an, &i, &j);
  102.     p[i][j] = mymove;
  103.     showboard();
  104.       }
  105.      else
  106.     cont = 0;
  107.    }
  108.   while (cont);
  109.  
  110. /* set empty to side they belong to */
  111.   for (i = 0; i < 19; i++)
  112.      for (j = 0; j < 19; j++)
  113.     if (p[i][j] == EMPTY)
  114.        p[i][j] = findcolor(i, j);
  115.  
  116. /* count total */
  117.   mtot = 0;  utot = 0;
  118.   for (i = 0; i < 19; i++)
  119.      for (j = 0; j < 19; j++)
  120.     if (p[i][j] == mymove)
  121.       ++mtot;
  122.     else
  123.        if (p[i][j] == umove)
  124.          ++utot;
  125.  
  126.   showboard();
  127.   printf("Your total number of pieces %d\n", utot);
  128.   printf("My total number of pieces %d\n", mtot);
  129.  
  130. }  /* end endgame */
  131.  
  132.